# Contributor: André Klitzing <aklitzing@gmail.com>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=ripgrep
pkgver=14.1.0
pkgrel=0
pkgdesc="ripgrep combines the usability of The Silver Searcher with the raw speed of grep"
url="https://github.com/BurntSushi/ripgrep"
arch="all"
license="MIT OR Unlicense"
makedepends="
	cargo
	cargo-auditable
	pcre2-dev
	"
checkdepends="xz"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="https://github.com/BurntSushi/ripgrep/archive/$pkgver/ripgrep-$pkgver.tar.gz
	"

export PCRE2_SYS_STATIC=0  # use system libpcre2
export JEMALLOC_SYS_WITH_LG_PAGE=16 # 2**16 = 64k

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen --features 'pcre2'
}

check() {
	cargo test --frozen --features 'pcre2'
}

package() {
	install -Dm755 target/release/rg \
		-t "$pkgdir"/usr/bin/

	mkdir -p "$pkgdir/usr/share/zsh/site-functions"
	target/release/rg --generate complete-zsh > "$pkgdir/usr/share/zsh/site-functions/_rg"

	mkdir -p "$pkgdir/usr/share/bash-completion/completions"
	target/release/rg --generate complete-bash > "$pkgdir/usr/share/bash-completion/completions/rg"

	mkdir -p "$pkgdir/usr/share/fish/vendor_completions.d"
	target/release/rg --generate complete-fish > "$pkgdir/usr/share/fish/vendor_completions.d/rg.fish"

	mkdir -p "$pkgdir/usr/share/man/man1"
	target/release/rg --generate man >  "$pkgdir/usr/share/man/man1/rg.1"
}

sha512sums="
b50044b6513f5caad1373c1cd4598779311bfce9f28092b90852ed9489c728b01ef5c91d4110d70a75ec08d977fbdd2a2da9cbf0b2820eb48b99f9ec3825e0a3  ripgrep-14.1.0.tar.gz
"
